const {ccclass, property} = cc._decorator;

/**
 * 商品项目
 */
@ccclass
export default class NewClass extends cc.Component {

    id: number

    @property(cc.Label)
    titleLabel: cc.Label;

    @property(cc.Sprite)
    imageSprite: cc.Sprite;

    @property(cc.Label)
    priceLabel: cc.Label;

    @property(cc.Node)
    buyBtn: cc.Node


    init(data: any = {}) {
        this.id = data.id
        this.titleLabel.string = data.title
        this.imageSprite.spriteFrame = data.image
        this.priceLabel.string = data.price
        if (data._can_buy) {
            this.buyBtn.active = true
        }
        if (typeof data.onBuy === "function") {
            this.buyBtn.on(cc.Node.EventType.TOUCH_START, data.onBuy.bind(data.target || this, this.id))
        }
    }

    // update (dt) {}
}
